﻿/**  版本信息模板在安装目录下，可自行修改。
* V_Draw.cs
*
* 功 能： N/A
* 类 名： V_Draw
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/12/7 1:00:57   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace BBPA.DAL
{
	/// <summary>
	/// 数据访问类:V_Draw
	/// </summary>
	public partial class V_Draw
	{
		public V_Draw()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BBPA.Model.V_Draw model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into V_Draw(");
			strSql.Append("id,StoreID,SupplierID,Money,State,Dateandtime,StoreNumber,StoreName,SupplierNumber,SupplierName,Description,StoreShortName,SupplierShortName,DateandtimeFinish)");
			strSql.Append(" values (");
			strSql.Append("@id,@StoreID,@SupplierID,@Money,@State,@Dateandtime,@StoreNumber,@StoreName,@SupplierNumber,@SupplierName,@Description,@StoreShortName,@SupplierShortName,@DateandtimeFinish)");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@StoreID", SqlDbType.Int,4),
					new SqlParameter("@SupplierID", SqlDbType.Int,4),
					new SqlParameter("@Money", SqlDbType.Money,8),
					new SqlParameter("@State", SqlDbType.TinyInt,1),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@StoreNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@StoreName", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierName", SqlDbType.NVarChar,50),
					new SqlParameter("@Description", SqlDbType.Text),
					new SqlParameter("@StoreShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@DateandtimeFinish", SqlDbType.DateTime)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.StoreID;
			parameters[2].Value = model.SupplierID;
			parameters[3].Value = model.Money;
			parameters[4].Value = model.State;
			parameters[5].Value = model.Dateandtime;
			parameters[6].Value = model.StoreNumber;
			parameters[7].Value = model.StoreName;
			parameters[8].Value = model.SupplierNumber;
			parameters[9].Value = model.SupplierName;
			parameters[10].Value = model.Description;
			parameters[11].Value = model.StoreShortName;
			parameters[12].Value = model.SupplierShortName;
			parameters[13].Value = model.DateandtimeFinish;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BBPA.Model.V_Draw model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update V_Draw set ");
			strSql.Append("id=@id,");
			strSql.Append("StoreID=@StoreID,");
			strSql.Append("SupplierID=@SupplierID,");
			strSql.Append("Money=@Money,");
			strSql.Append("State=@State,");
			strSql.Append("Dateandtime=@Dateandtime,");
			strSql.Append("StoreNumber=@StoreNumber,");
			strSql.Append("StoreName=@StoreName,");
			strSql.Append("SupplierNumber=@SupplierNumber,");
			strSql.Append("SupplierName=@SupplierName,");
			strSql.Append("Description=@Description,");
			strSql.Append("StoreShortName=@StoreShortName,");
			strSql.Append("SupplierShortName=@SupplierShortName,");
			strSql.Append("DateandtimeFinish=@DateandtimeFinish");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@StoreID", SqlDbType.Int,4),
					new SqlParameter("@SupplierID", SqlDbType.Int,4),
					new SqlParameter("@Money", SqlDbType.Money,8),
					new SqlParameter("@State", SqlDbType.TinyInt,1),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@StoreNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@StoreName", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierName", SqlDbType.NVarChar,50),
					new SqlParameter("@Description", SqlDbType.Text),
					new SqlParameter("@StoreShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@SupplierShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@DateandtimeFinish", SqlDbType.DateTime)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.StoreID;
			parameters[2].Value = model.SupplierID;
			parameters[3].Value = model.Money;
			parameters[4].Value = model.State;
			parameters[5].Value = model.Dateandtime;
			parameters[6].Value = model.StoreNumber;
			parameters[7].Value = model.StoreName;
			parameters[8].Value = model.SupplierNumber;
			parameters[9].Value = model.SupplierName;
			parameters[10].Value = model.Description;
			parameters[11].Value = model.StoreShortName;
			parameters[12].Value = model.SupplierShortName;
			parameters[13].Value = model.DateandtimeFinish;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from V_Draw ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Draw GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,StoreID,SupplierID,Money,State,Dateandtime,StoreNumber,StoreName,SupplierNumber,SupplierName,Description,StoreShortName,SupplierShortName,DateandtimeFinish from V_Draw ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			BBPA.Model.V_Draw model=new BBPA.Model.V_Draw();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Draw DataRowToModel(DataRow row)
		{
			BBPA.Model.V_Draw model=new BBPA.Model.V_Draw();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["StoreID"]!=null && row["StoreID"].ToString()!="")
				{
					model.StoreID=int.Parse(row["StoreID"].ToString());
				}
				if(row["SupplierID"]!=null && row["SupplierID"].ToString()!="")
				{
					model.SupplierID=int.Parse(row["SupplierID"].ToString());
				}
				if(row["Money"]!=null && row["Money"].ToString()!="")
				{
					model.Money=decimal.Parse(row["Money"].ToString());
				}
				if(row["State"]!=null && row["State"].ToString()!="")
				{
					model.State=int.Parse(row["State"].ToString());
				}
				if(row["Dateandtime"]!=null && row["Dateandtime"].ToString()!="")
				{
					model.Dateandtime=DateTime.Parse(row["Dateandtime"].ToString());
				}
				if(row["StoreNumber"]!=null)
				{
					model.StoreNumber=row["StoreNumber"].ToString();
				}
				if(row["StoreName"]!=null)
				{
					model.StoreName=row["StoreName"].ToString();
				}
				if(row["SupplierNumber"]!=null)
				{
					model.SupplierNumber=row["SupplierNumber"].ToString();
				}
				if(row["SupplierName"]!=null)
				{
					model.SupplierName=row["SupplierName"].ToString();
				}
				if(row["Description"]!=null)
				{
					model.Description=row["Description"].ToString();
				}
				if(row["StoreShortName"]!=null)
				{
					model.StoreShortName=row["StoreShortName"].ToString();
				}
				if(row["SupplierShortName"]!=null)
				{
					model.SupplierShortName=row["SupplierShortName"].ToString();
				}
				if(row["DateandtimeFinish"]!=null && row["DateandtimeFinish"].ToString()!="")
				{
					model.DateandtimeFinish=DateTime.Parse(row["DateandtimeFinish"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,StoreID,SupplierID,Money,State,Dateandtime,StoreNumber,StoreName,SupplierNumber,SupplierName,Description,StoreShortName,SupplierShortName,DateandtimeFinish ");
			strSql.Append(" FROM V_Draw ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,StoreID,SupplierID,Money,State,Dateandtime,StoreNumber,StoreName,SupplierNumber,SupplierName,Description,StoreShortName,SupplierShortName,DateandtimeFinish ");
			strSql.Append(" FROM V_Draw ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM V_Draw ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from V_Draw T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "V_Draw";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

